import myAxios from "@/util/request";

/**
 * 添加商品
 */
export const addProduct = (data: {
    name: string;
    description: string;
    categoryId: number;
    basePrice: number;
    imageList: string[];
    sort: number;
}) => {
    return myAxios({
        url: '/product/add',
        method: 'POST',
        headers: {
            'token': localStorage.getItem('token')
        },
        data
    });
};

/**
 * 修改商品
 */
export const modifyProduct = (data: {
    productId: number;
    name: string;
    description: string;
    categoryId: number;
    basePrice: number;
    imageList: string[];
    sort: number;
}) => {
    return myAxios({
        url: '/product/modify',
        method: 'POST',
        headers: {
            'token': localStorage.getItem('token')
        },
        data
    });
};

/**
 * 删除商品
 */
export const delProduct = (id: number) => {
    return myAxios({
        url: '/product/del',
        method: 'GET',
        headers: {
            'token': localStorage.getItem('token')
        },
        params: {
            "id": id
        }
    });
};

/**
 * 商品列表
 */
export const listAllProduct = (pageSize:number, pageNum: number, name?: string) => {
    return myAxios({
        url: '/product/listProduct',
        method: 'GET',
        headers: {
            'token': localStorage.getItem('token')
        },
        params: {
            "pageSize": pageSize,
            "pageNum": pageNum,
            "name": name
        }
    });
};

/**
 * 商品详情
 */
export const productDetailWithParam = (storeId:string, productId: number) => {
    return myAxios({
        url: '/product/detailWithParam',
        method: 'GET',
        headers: {
            'token': localStorage.getItem('token')
        },
        params: {
            "storeId": storeId,
            "productId": productId
        }
    });
};

/**
 * 商品上下架
 */
export const operationProduct = (storeId:string, productId: number, op: number) => {
    return myAxios({
        url: '/product/operationProduct',
        method: 'GET',
        headers: {
            'token': localStorage.getItem('token')
        },
        params: {
            "storeId": storeId,
            "productId": productId,
            "op": op
        }
    });
};

export const changeProductTemplate = (storeId:string, productId: number, templateId: number) => {
    return myAxios({
        url: '/store/changeTemplate',
        method: 'GET',
        headers: {
            'token': localStorage.getItem('adminToken')
        },
        params: {
            "storeId": storeId,
            "productId": productId,
            "templateId": templateId
        }
    });
}
